<template>
  <div>
    <el-dialog :modelValue="visiable" title="新增工程" width="500" @close="$emit('close')">
      <el-form label-width="80px" :inline="false" class="form">
        <el-form-item label="工程名称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="工程简称">
          <el-input v-model="form.shortName"></el-input>
        </el-form-item>
        <el-form-item label="分公司">
          <el-select v-model="form.company" clearable filterable>
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="电压等级">
          <el-select v-model="form.dianya" clearable filterable>
            <el-option v-for="item in dianyaOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button @click="onClose">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'

import useProj from '@renderer/composables/useProj'
import { ElMessage } from 'element-plus'

defineProps(['visiable'])
const emit = defineEmits(['close'])
const { add } = useProj()
const form = reactive({
  name: '皖电东送淮南至上海特高压输电示范工程',
  shortName: '1000千伏淮上线',
  company: '线一',
  dianya: '1000kV',
})
const options = [
  { label: '线一', value: '线一' },
  { label: '线二', value: '线二' },
  { label: '天心', value: '天心' },
]
const dianyaOptions = [
  { label: '220kV', value: '220kV' },
  { label: '500kV', value: '500kV' },
  { label: '750kV', value: '750kV' },
  { label: '±800kV', value: '±800kV' },
  { label: '1000kV', value: '1000kV' },
]
const onSubmit = async () => {
  await add(form)
  ElMessage({
    message: '添加工程成功',
    type: 'success',
  })
  emit('close')
}
const onClose = () => {
  emit('close')
}
</script>

<style lang="scss" scoped>
.form {
  @apply mt-3;
}
</style>
